package com.naiterui.ehp.bs.patient.validation;

import org.slf4j.Logger;

import com.naiterui.ehp.bp.domain.Patient;
import org.slf4j.LoggerFactory;
import com.naiterui.ehp.bs.patient.exception.ExceptionCodes;
import com.naiterui.ehp.bs.patient.utils.exception.PatientBusinessException;

/**
 * 患者信息校验工具类
 * @author Amber
 * @since 1.0.0
 */
public class PatientValidation {

    private static final Logger LOGGER = LoggerFactory.getLogger(PatientValidation.class);

    /**
     * 患者用户存在<P>
     * PatientValidation.existValidate()
     * @Author Amber
     * @Date 2016年2月27日
     * @since 1.0.0
     * @param patient
     * @param operationInfo 操作信息
     * @throws PatientBusinessException
     */
    public static void existValidate(Patient patient, String operationInfo, Object... arguments) throws PatientBusinessException {
        if (patient == null || patient.getId() == null) {
            LOGGER.error("{} ;patient not exist!", operationInfo, arguments);
            throw new PatientBusinessException(ExceptionCodes.PATIENT_NOT_EXIST);
        }
    }

    /**
     * 患者用户存在且账户正常<P>
     * PatientValidation.accountStatusValidate()
     * @Author Amber
     * @Date 2016年2月27日
     * @since 1.0.0
     * @param patient
     * @param operationInfo 操作信息
     * @throws PatientBusinessException
     */
    public static void accountStatusValidate(Patient patient, String operationInfo, Object... arguments) throws PatientBusinessException {
        existValidate(patient, operationInfo, arguments);
        if (patient.getAccountStatus() != 0) {
            LOGGER.error("{};patient account status error。", operationInfo, arguments);
            throw new PatientBusinessException(ExceptionCodes.PATIENT_ACCOUNT_ERROR);
        }
    }
}
